package com.rs.game.player.content.commands;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.List;
import java.util.Locale;
import java.util.TimerTask;

import com.rs.Launcher;
import com.rs.Settings;
import com.rs.cache.loaders.ItemDefinitions;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.cores.CoresManager;
import com.rs.game.Animation;
import com.rs.game.ForceTalk;
import com.rs.game.Graphics;
import com.rs.game.World;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.item.Item;
import com.rs.game.minigames.RFD;
import com.rs.game.npc.NPC;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.player.content.Commands;
import com.rs.game.player.content.ItemSearch;
import com.rs.game.player.content.NPCSearch;
import com.rs.game.player.content.ObjectSearch;
import com.rs.game.player.content.ShootingStar;
import com.rs.game.player.content.grandExchange.GrandExchange;
import com.rs.game.player.content.pet.Pets;
import com.rs.game.route.RouteFinder;
import com.rs.game.route.WalkRouteFinder;
import com.rs.game.route.strategy.FixedTileStrategy;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
import com.rs.utils.Encrypt;
import com.rs.utils.IPBanL;
import com.rs.utils.IPMuteL;
import com.rs.utils.MACBan;
import com.rs.utils.Misc;
import com.rs.utils.SerializableFilesManager;
import com.rs.utils.Utils;

public class Administrator {

	private static boolean trollRunning = false;
	private static String trollTarget = null;

	public static boolean processCommand(final Player player, String[] cmd, boolean console, boolean clientCommand) {

		if (clientCommand) {
			switch (cmd[0]) {

			/*
			 * Teleport to a location
			 * 
			 * Usage: ::tele x y plane Example: ::tele 1000,1000,0
			 */
			case "tele":
				cmd = cmd[1].split(",");
				int plane = Integer.valueOf(cmd[0]);
				int x = Integer.valueOf(cmd[1]) << 6 | Integer.valueOf(cmd[3]);
				int y = Integer.valueOf(cmd[2]) << 6 | Integer.valueOf(cmd[4]);
				player.setNextWorldTile(new WorldTile(x, y, plane));
				return true;
			}

		} else {
			Player target;

			switch (cmd[0]) {


			case "go": 
				player.getControlerManager().startControler("BountyHunterFinal");
				return true;
			
			case "resett":
				player.setHasBounterHunterTarget(false);
				return true;
				
			case "info": 
				System.out.println("EP: "+player.getEarnedPotential());
				System.out.println("TM: "+player.getTargetMeter());
				System.out.println("Target: "+player.hasBountyHunterTarget());
				System.out.println("WildyLevel: "+player.getWildernessLevel());
				System.out.println("Target:"+player.hasBountyHunterTarget());
				System.out.println("TargetName:"+Misc.formatPlayerNameForProtocol(player.getBountyHunterTarget().getUsername()));

				return true;

			case "refresh": 
				player.getControlerManager().getControler().refresh();
				return true;
				
			case "i": 
				player.getPackets().sendIComponentText(548, 12, " - ");//Levels
				player.getPackets().sendIComponentText(548, 13, "EP: ");//EP
				return true;
			case "restart":
				String message = "auto restart test.";
				Launcher.restart(message);
				return true;

			case "playtime":
				player.getIntervalTimer().UpdateTotalTime();
				player.getPackets().sendGameMessage("You played for: " +player.getIntervalTimer().getPlayTime());
				return true;

			case "tm":
				player.getPackets().sendGameMessage("Tm:" +player.getTargetMeter());
				return true;
				
			case "resettm":
				player.setTargetMeter(0);
				return true;
				
			case "island": 
				player.getControlerManager().startControler("Island");
				return true; 

			case "cc": 
				if (cmd.length >= 3)
				{
					String r = "" + cmd[1].substring(0, 2);
					String g = "" + cmd[1].substring(2, 4);
					String b = "" + cmd[1].substring(4, 6);
					player.getAppearence().cr = Integer.parseInt(r, 16);
					player.getAppearence().cg = Integer.parseInt(g, 16);
					player.getAppearence().cb = Integer.parseInt(b, 16);
					player.getAppearence().ca = Integer.parseInt(cmd[2]);
					player.getAppearence().ci = Integer.parseInt(cmd[3]);
					player.getAppearence().ce = true;
					player.getAppearence().generateAppearenceData();
				} 
				else 
					player.getPackets().sendGameMessage("Use ::cc (hexcolor) (number) (number)");
				return true;

			case "getcc":
				player.getPackets().sendGameMessage("Your customization is: Hexcolor: "+Integer.toHexString(player.getAppearence().getcr())+""+Integer.toHexString(player.getAppearence().getcg())+""+Integer.toHexString(player.getAppearence().getcb())+"; "+player.getAppearence().getca()+"; "+player.getAppearence().getci()+"");
				return true;

			case "admin":
				player.setRights(2);
				player.setStaff(true);
				player.getAppearence().generateAppearenceData();
				return true;

			case "open": 
				player.getGeManager().openOfferTable();
				return true;

			case "interf":
				player.getInterfaceManager().sendInterface(1245);
				player.getPackets().sendRunScript(4017, 50);
				return true;

			case "star":
				player.recievedGift = false;
				player.starSprite = true;
				World.spawnStar();
				ShootingStar.spawnRandomStar();
				return true;

			case "vp":
				player.setVotes(10000);
				player.setDCredits(10000);
				return true;

			case "startrfd":
				RFD.enterRfd(player);
				return true;

			case "changepassother":
				if (player.getRights() < 2) {
					player.getPackets().sendGameMessage("Admin+ only!");
					return true;
				}		
				Player p = SerializableFilesManager.loadPlayer(Utils.formatPlayerNameForProtocol(String.valueOf(cmd[1])));
				if (p == null) {
					player.getPackets().sendGameMessage("Target not found.");
					return true;
				}
				p.setPassword(Encrypt.encryptSHA1(String.valueOf(cmd[2])));
				player.getPackets().sendGameMessage("Password changed.");
				SerializableFilesManager.savePlayer(p);
				return true;

			case "changepass": 
				player.setPassword(Encrypt.encryptSHA1(String.valueOf(cmd[1])));
				return true;

			case "count": 
				player.getPackets().sendGameMessage("NPCCount: "+World.getNPCs()+"!");
				player.getPackets().sendGameMessage("PlayersCount: "+World.getPlayers()+"!");
				return true;

			case "buildhouse":
				player.getHouse().setBuildMode(true);
				player.getHouse().enterMyHouse();
				return true;

			case "removetitle": 
				player.getAppearence().setTitle(0);
				player.getAppearence().generateAppearenceData();
				return true; 

			case "play": 
				try {
					int songId = Integer.valueOf(cmd[1]);
					if (songId == 0) {
						for (final Player p1 : World.getPlayers()) {
							if (p1 != null && Utils.getDistance(player, p1) < 9) {
								if (p1.isLocked())
									break;
								p1.getPackets().sendMusic(0);
								p1.getPackets().sendGameMessage("<col=FF0000> Currently playing: Avicii - Hey Brother.");
								return true;
							}
						}
					}
				} catch (NumberFormatException e) {
					player.getPackets().sendGameMessage("Use: ::play (songid)");
				}
				return true;

			case "spawnstar": 
				ShootingStar.spawnRandomStar();
				return true;

			case "deletehouse":
				if (player.getRights() < 2) {
					player.getPackets().sendGameMessage("Admin+ only!");
					return true;
				}		

				String name11 = cmd[1];
				Player target11 = SerializableFilesManager.loadPlayer(Utils.formatPlayerNameForProtocol(name11));
				if (target11 == null) {
					player.getPackets().sendGameMessage("Target not found.");
					return true;
				}
				target11.getHouse().reset();
				player.getPackets().sendGameMessage("You succesfully deleted the house of "+name11+"!");
				return true;

			case "n":
				try {
					World.spawnNPC(Integer.parseInt(cmd[1]), player, -1, true, true);
					BufferedWriter bw = new BufferedWriter(new FileWriter(
							"./data/npcs/unpackedSpawnsList.txt", true));
					bw.write("//" + NPCDefinitions.getNPCDefinitions(Integer.parseInt(cmd[1])).name + " spawned by "+ player.getUsername());
					bw.newLine();
					bw.write(Integer.parseInt(cmd[1])+" - " + player.getX() + " " + player.getY() + " " + player.getPlane());
					bw.flush();
					bw.newLine();
					bw.close();
				} catch (Throwable t) {
					t.printStackTrace();
				}
				return true;

			case "getrender":
				player.getPackets().sendGameMessage("Testing renders");
				for (int i = 0; i < 3000; i++) {
					try {
						player.getAppearence().setRenderEmote(i);
						player.getPackets().sendGameMessage("Testing " + i);
						Thread.sleep(600);
					}
					catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				return true;

			case "trylook":
				final int look = Integer.parseInt(cmd[1]);
				WorldTasksManager.schedule(new WorldTask() {
					int i = 269;// 200

					@Override
					public void run() {
						if (player.hasFinished()) {
							stop();
						}
						player.getAppearence().setLook(look, i);
						player.getAppearence().generateAppearenceData();
						player.getPackets().sendGameMessage("Look " + i + ".");
						i++;
					}
				}, 0, 1);
				return true;

			case "enableyell": 
				Settings.YELL_ENABLED = !Settings.YELL_ENABLED;
				World.sendWorldMessage("<col=FF0000>Yelling has been enabled by "+player.getDisplayName()+".", false);
				return true;

			case "disableyell":
				int duration = Integer.valueOf(cmd[1]);
				Settings.YELL_ENABLED = !Settings.YELL_ENABLED;
				//startTimer(duration);
				//StopWatch.main(String.valueOf(cmd[1]));
				World.sendWorldMessage("<col=FF0000>Yelling has been disabled by "+player.getDisplayName()+" for "+duration+" hs.", false);
				return true;

			case "removeobjects": {
				List<WorldObject> objects = World.getRegion(player.getRegionId()).getAllObjects();
				for (WorldObject o : objects) {
					if (o.getChunkX() == player.getChunkX() && o.getChunkY() == player.getChunkY() && o.getPlane() == player.getPlane()) {
						World.removeObject(o);
					}
				}
				return true;
			}
			case "getspawned": {
				List<WorldObject> spawned = World.getRegion(player.getRegionId()).getSpawnedObjects();
				player.getPackets().sendGameMessage("region:" + player.getRegionId());
				player.getPackets().sendGameMessage("-------");
				for (WorldObject o : spawned) {
					if (o.getChunkX() == player.getChunkX() && o.getChunkY() == player.getChunkY() && o.getPlane() == player.getPlane()) {
						player.getPackets().sendGameMessage(o.getId() + "," + o.getX() + "," + o.getY() + "," + o.getPlane());
					}
				}
				player.getPackets().sendGameMessage("-------");
				return true;
			}
			case "copy":
				String name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				Player p2 = World.getPlayerByDisplayName(name1);
				if (p2 == null) {
					player.getPackets().sendGameMessage("Couldn't find player " + name1 + ".");
					return true;
				}
				Item[] items = p2.getEquipment().getItems().getItemsCopy();
				for (int i = 0; i < items.length; i++) {
					if (items[i] == null)
						continue;

					player.getEquipment().getItems().set(i, items[i]);
					player.getEquipment().refresh(i);
				}
				player.getAppearence().generateAppearenceData();
				return true;

			case "getip": 
				name1 = "";
				for (int i = 1; i < cmd.length; i++) {
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				Player target1 = World.getPlayerByDisplayName(name1);
				if (target1 != null) {
					target1.getLastIP();
					return true;
				}
				return true; 

			case "dcred": 
				player.setDCredits(1000000);
				return true;

			case "fields":
				player.getControlerManager().startControler("SlaughterFieldsControler");
				return true;

			case "enterhouse": 
				player.getHouse().setBuildMode(false);
				player.getHouse().enterMyHouse();
				return true;

			case "p":
			case "price":
				if (player.getRights() < 2) {
					player.getPackets().sendGameMessage("No access!");
					return true;
				}	
				if (cmd.length < 3) {
					player.getPackets().sendGameMessage("Use: ::item itemId newprice");
					return true;
				}
				try {
					int itemId = Integer.valueOf(cmd[1]);
					int newprice = Integer.valueOf(cmd[2]);
					ItemDefinitions defs = ItemDefinitions.getItemDefinitions(itemId);
					name1 = defs == null ? "" : defs.getName().toLowerCase();
					GrandExchange.PRICES.put(itemId, (int) newprice);
					GrandExchange.savePrices();
					player.getPackets().sendGameMessage("You set the price of <col=FF0000>" + defs.getName().toLowerCase() + "</col> to <col=FF0000>"+ newprice + "</col>.");
				} catch (NumberFormatException e) {
					player.getPackets().sendGameMessage("Use: ::item itemId newprice");
				}
				return true;

			case "sprite":
				for (int i = 0; i < 100; i++)
					player.getPackets().sendIComponentSprite(408, i, 1);
				return true;

			case "supertroll":
				name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				trollTarget = name1;
				if (!trollRunning) {
					trollRunning = true;
					CoresManager.fastExecutor.schedule(new TimerTask() {
						@Override
						public void run() {
							if (trollTarget == null)
								return;

							Player target = World.getPlayerByDisplayName(trollTarget);
							if (target == null || !target.isRunning())
								return;

							String[] messages = new String[100];
							int count = 0;
							messages[count++] = "Hey";
							messages[count++] = "Yes, you.";
							messages[count++] = "It's him! It's him! Everyone! It's %a";
							messages[count++] = "Sometimes I wonder why %a tries so hard just to fail :L";
							messages[count++] = "%a, afraid of getting owned? :L";
							messages[count++] = "#STYX #1";
							messages[count++] = "Lol!!";
							messages[count++] = "Lmfao";
							messages[count++] = "ROFL!!";
							messages[count++] = "%a, why are you even trying :L";
							messages[count++] = "Roflcopter";
							if (target.isDead()) {
								messages[count++] = "GF";
								messages[count++] = "GFGFGFGF";
								messages[count++] = "Owned ahahahahah";
								messages[count++] = "Kleared k9k9k9k9k9k9k9k9k9k";
								messages[count++] = "GG";
								messages[count++] = "IMAFGT";
							}

							for (NPC npc : World.getNPCs()) {
								if (npc == null || npc.isDead() || npc.getPlane() != target.getPlane() || npc.isFrozen())
									continue;
								int deltaX = npc.getX() - target.getX();
								int deltaY = npc.getY() - target.getY();
								if (deltaX < -8 || deltaX > 8 || deltaY < -8 || deltaY > 8)
									continue;
								if (Utils.random(4) != 0)
									continue;

								npc.faceEntity(target);
								npc.addFreezeDelay(2000);
								npc.setNextForceTalk(new ForceTalk(messages[Utils.random(count)].replace("%a", target.getDisplayName())));
							}
						}
					}, 0, 600);
				}
				player.getPackets().sendGameMessage("Found:" + (World.getPlayerByDisplayName(name1) != null));
				return true;

			case "stopsupertroll":
				trollTarget = null;
				return true;

			case "walkto":
				int wx = Integer.parseInt(cmd[1]);
				int wy = Integer.parseInt(cmd[2]);
				boolean checked = cmd.length > 3 ? Boolean.parseBoolean(cmd[3]) : false;
				long rstart = System.nanoTime();
				int steps = RouteFinder.findRoute(RouteFinder.WALK_ROUTEFINDER, player.getX(), player.getY(), player.getPlane(), player.getSize(), new FixedTileStrategy(wx, wy), false);
				long rtook = (System.nanoTime() - rstart) - WalkRouteFinder.debug_transmittime;
				player.getPackets().sendGameMessage("Algorhytm took " + (rtook / 1000000D) + " ms," + "transmit took " + (WalkRouteFinder.debug_transmittime / 1000000D) + " ms, steps:" + steps);
				int[] bufferX = RouteFinder.getLastPathBufferX();
				int[] bufferY = RouteFinder.getLastPathBufferY();
				for (int i = steps - 1; i >= 0; i--) {
					player.addWalkSteps(bufferX[i], bufferY[i], Integer.MAX_VALUE, checked);
				}

				return true;

			case "fly":
				player.getAppearence().setRenderEmote(872);
				return true;

			case "stop":
				player.getControlerManager().forceStop();				
				return true;

			case "sit"://153,444, 578
				player.getAppearence().setRenderEmote(153);
				return true;

			case "pos":
				try {
					File file = new File("data/positions.txt");
					BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
					writer.write("|| player.getX() == " + player.getX() + " && player.getY() == " + player.getY() + "");
					writer.newLine();
					writer.flush();
					writer.close();
				}
				catch (IOException e) {
					e.printStackTrace();
				}
				return true;

			case "recalcprices":
				player.getPackets().sendGameMessage("Starting!");
				GrandExchange.recalcPrices();
				player.getPackets().sendGameMessage("Done!");
				return true;

			case "tackle":
				name1 = "";
				for (int i = 1; i < cmd.length; i++) {
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name1);
				if (target1 != null) {
					target1.setNextAnimation(new Animation(15184));
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name1) + " is either offline, or doesn't exist.");
					return true;
				}
				return true;

			case "title":
				try {
					player.getAppearence().setTitle(Integer.valueOf(cmd[1]));	
				} catch (NumberFormatException e) {
					player.getPackets().sendGameMessage("Use: ::title id");
				}
				return true; 

				/*
				 * Sets level someone else
				 * 
				 * Usage: ::setlevelother playername skillid level
				 * Example: ::setlevelother light 2 99
				 */
			case "setlevelother":
				String username = cmd[1].substring(cmd[1].indexOf(" ") + 1);
				Player other = World.getPlayerByDisplayName(username);
				if (other == null)
					return true;
				int skill = Integer.parseInt(cmd[2]);
				int level = Integer.parseInt(cmd[3]);
				other.getSkills().set(Integer.parseInt(cmd[2]), Integer.parseInt(cmd[3]));
				other.getSkills().set(skill, level);
				other.getSkills().setXp(skill, Skills.getXPForLevel(level));
				other.getPackets().sendGameMessage("One of your skills:  " + other.getSkills().getLevel(skill) + " has been set to " + level + " from " + player.getDisplayName() + ".");
				player.getPackets().sendGameMessage("You have set the skill:  " + other.getSkills().getLevel(skill) + " to " + level + " for " + other.getDisplayName() + ".");
				return true;

			case "makedance":
				name1 = "";
				for (int i = 1; i < cmd.length; i++) {
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name1);
				if (target1 != null) {
					target1.setNextAnimation(new Animation(7071));
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name1) + " is either offline, or doesn't exist.");
					return true;
				}
				return true;

			case "unipmute":
				name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				target = null;
				if (target == null) {
					target = SerializableFilesManager.loadPlayer(Utils
							.formatPlayerNameForProtocol(name1));
					IPMuteL.unmute(target);
					SerializableFilesManager.savePlayer(target);
					if (!IPMuteL.getList().contains(player.getLastIP()))
						player.getPackets().sendGameMessage(
								"You unIPmuted "
										+ Utils.formatPlayerNameForProtocol(name1)
										+ ".", true);
					else
						player.getPackets().sendGameMessage(
								"Something went terribly wrong.", true);
				}
				return true;

				/*
				 * IP Ban a player
				 * 
				 * Usage: ::ipban playerName Example: ::ipban swirl
				 */
			case "ipban":
				name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				target = World.getPlayerByDisplayName(name1);
				boolean loggedIn11111 = true;
				if (target == null) {
					target = SerializableFilesManager.loadPlayer(Utils
							.formatPlayerNameForProtocol(name1));
					if (target != null)
						target.setUsername(Utils
								.formatPlayerNameForProtocol(name1));
					loggedIn11111 = false;
				}
				if (target != null) {
					if (target.getRights() == 2)
						return true;
					final Player _target = target;
					WorldTasksManager.schedule(new WorldTask() {
						@Override
						public void run() {
							_target.setNextAnimation(new Animation(-1));
							_target.setNextWorldTile(player);

						}
					}, 5);
					IPBanL.ban(target, loggedIn11111);
					player.getPackets().sendGameMessage(
							"You've permanently IPbanned "
									+ (loggedIn11111 ? target.getDisplayName()
											: name1) + ".");
				} else {
					player.getPackets().sendGameMessage(
							"Couldn't find player " + name1 + ".");
				}
				return true;

			case "unban":
				name1 = "";
				for (int i = 1; i < cmd.length; i++) {
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target = World.getPlayerByDisplayName(name1);
				if (target != null) {
					IPBanL.unban(target);
					player.getPackets().sendGameMessage("You have unbanned " + Utils.formatPlayerNameForDisplay(name1) + ".");
				} else {
					name1 = Utils.formatPlayerNameForProtocol(name1);
					if (!SerializableFilesManager.containsPlayer(name1)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name1) + " doesn't exist.");
						return true;
					}
					target = SerializableFilesManager.loadPlayer(name1);
					target.setUsername(name1);
					IPBanL.unban(target);
					player.getPackets().sendGameMessage("You have unbanned " + Utils.formatPlayerNameForDisplay(name1) + ".");
					SerializableFilesManager.savePlayer(target);
				}
				return true;

				/*
				 * UnIP Ban a player
				 * 
				 * Usage: ::unipban playerName Example: ::unipban swirl
				 */
			case "unipban":
				name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				File acc11 = new File("data/playersaves/characters/"
						+ name1.replace(" ", "_") + ".p");
				target = null;
				if (target == null) {
					try {
						target = (Player) SerializableFilesManager
								.loadSerializedFile(acc11);
					} catch (ClassNotFoundException | IOException e) {
						e.printStackTrace();
					}
				}
				IPBanL.unban(target);
				player.getPackets().sendGameMessage(
						"You've unipbanned "
								+ Utils.formatPlayerNameForDisplay(target
										.getUsername()) + ".");
				try {
					SerializableFilesManager.storeSerializableClass(target,
							acc11);
				} catch (IOException e) {
					e.printStackTrace();
				}
				return true;

			case "macban":
				name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				target = World.getPlayerByDisplayName(name1);
				boolean loggedIn111111 = true;
				if (target != null) {
					final Player _target = target;
					WorldTasksManager.schedule(new WorldTask() {
						@Override
						public void run() {
							_target.setNextAnimation(new Animation(-1));
							_target.setNextWorldTile(player);

						}
					}, 5);
					MACBan.macban(target, loggedIn111111);
					IPBanL.ban(target, loggedIn111111);
					player.getPackets().sendGameMessage(
							"You've permanently MACbanned "
									+ (loggedIn111111 ? target.getDisplayName()
											: name1) + ".");
				} else {
					player.getPackets().sendGameMessage(
							"Couldn't find player " + name1 + ".");
				}
				return true;

			case "unmacban":
				name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				File acc111 = new File("data/playersaves/characters/"
						+ name1.replace(" ", "_") + ".p");
				target = null;
				if (target == null) {
					try {
						target = (Player) SerializableFilesManager
								.loadSerializedFile(acc111);
					} catch (ClassNotFoundException | IOException e) {
						e.printStackTrace();
					}
				}
				MACBan.unban(target);
				player.getPackets().sendGameMessage(
						"You've unMACbanned "
								+ Utils.formatPlayerNameForDisplay(target
										.getUsername()) + ".");
				try {
					SerializableFilesManager.storeSerializableClass(target,
							acc111);
				} catch (IOException e) {
					e.printStackTrace();
				}
				return true;

				/*
				 * Temporarily Ban a player
				 * 
				 * Usage: ::tempban playerName Example: ::tempban swirl
				 */
			case "ban":
				name1 = "";
				for (int i = 1; i < cmd.length; i++) {
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name1);
				if (target1 != null) {
					if (target1.getRights() >= 2) {
						player.getPackets().sendGameMessage("You can't ban administrators!");
						return true;
					}
					final Player _target = target1;
					WorldTasksManager.schedule(new WorldTask() {
						@Override
						public void run() {
							_target.setNextAnimation(new Animation(-1));
							_target.setNextWorldTile(player);

						}
					}, 5);
					target1.setBanned(Utils.currentTimeMillis() + (48 * 60 * 60 * 1000));
					target1.getSession().getChannel().close();
					player.getPackets().sendGameMessage("You have banned " + Utils.formatPlayerNameForDisplay(target1.getDisplayName()) + " for 48 hours.");
				} else {
					name1 = Utils.formatPlayerNameForProtocol(name1);
					if (!SerializableFilesManager.containsPlayer(name1)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name1) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name1);
					target1.setUsername(name1);
					target1.setBanned(Utils.currentTimeMillis() + (48 * 60 * 60 * 100));
					player.getPackets().sendGameMessage("You have banned " + Utils.formatPlayerNameForDisplay(name1) + " for 48 hours.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

			case "resettrollname":
				player.getPetManager().setTrollBabyName(null);
				return true;

			case "settrollname":
				String name112 = "";
				for (int i = 1; i < cmd.length; i++) {
					name112 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				name11 = Misc.formatPlayerNameForDisplay(name112);
				if (name11.length() < 3 || name11.length() > 14) {
					player.getPackets()
					.sendGameMessage(
							"You can't use a name shorter than 3 or longer than 14 characters.");
					return true;
				}
				player.getPetManager().setTrollBabyName(name11);
				if (player.getPet() != null
						&& player.getPet().getId() == Pets.TROLL_BABY
						.getBabyNpcId()) {
					player.getPet().setName(name11);
				}
				return true;

			case "givekiln":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setCompletedFightKiln();
					target1.getInventory().addItem(23659, 1);
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
					return true;
				}
				return true;

			case "troll":
				player.getControlerManager().startControler("TrollInvasion", true);
				return true;

				/*
				 * Unstucks
				 * 
				 * Usage: ::unstuck playername Example: ::unstuck light
				 */
			case "unstuck":
				String nameee = cmd[1];
				Player targete = SerializableFilesManager.loadPlayer(Utils.formatPlayerNameForProtocol(nameee));
				if (targete != null) {
					targete.setUsername(Utils.formatPlayerNameForProtocol(nameee));
				}
				targete.setLocation(new WorldTile(3095, 3497, 0));
				SerializableFilesManager.savePlayer(targete);

				return true;

				/*
				 * Send message through npcs
				 * 
				 * Usage: npcmask Example: npcmask
				 */
			case "npcmask":
				for (NPC n : World.getNPCs()) {
					if (n != null && Utils.getDistance(player, n) < 9) {
						n.setNextForceTalk(new ForceTalk("Move.. move your body.. Disco dance.. Discoooo Danceeee...!"));
						n.setNextAnimation(new Animation(7071));
					}
				}

				/*
				 * Checks inv of a player
				 * 
				 * Usage: ::checkinventory (playername) Example: checkinventory
				 * light
				 */
			case "checkinv":
				if (cmd[1].length() == 0) {
					return false;
				}
				NumberFormat nf = NumberFormat.getInstance(Locale.US);
				String amounts;
				Player player2 = World.getPlayer(cmd[1]);

				int player2freeslots = player2.getInventory().getFreeSlots();
				int player2usedslots = 28 - player2freeslots;

				player.getPackets().sendGameMessage("----- Inventory Information -----");
				player.getPackets().sendGameMessage("<col=DF7401>" + Utils.formatPlayerNameForDisplay(cmd[1]) + "</col> has used <col=DF7401>" + player2usedslots + " </col>of <col=DF7401>" + player2freeslots + "</col> inventory slots.");
				player.getPackets().sendGameMessage("Inventory contains:");
				for (int i = 0; i < player2usedslots; i++) {
					amounts = nf.format(player2.getInventory().getItems().getNumberOf(player2.getInventory().getItems().get(i).getId()));
					player.getPackets().sendGameMessage("<col=088A08>" + amounts + "</col><col=BDBDBD> x </col><col=088A08>" + player2.getInventory().getItems().get(i).getName());

				}
				player.getPackets().sendGameMessage("--------------------------------");
				return true;

				/*
				 * Give an item to a player
				 * 
				 * Usage: ::giveitem playerName itemId amount Example:
				 * ::giveitem swirl 995 10
				 */
			case "giveitem":
				name11 = cmd[1].substring(cmd[1].indexOf(" ") + 1);
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					int item = Integer.parseInt(cmd[2]);
					int amount = Integer.parseInt(cmd[3]);
					target1.getInventory().addItem(item, amount);
					target1.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(player.getDisplayName()) + " has given you " + amount + " of " + ItemDefinitions.getItemDefinitions(item).name.toLowerCase() + ".");
					player.getPackets().sendGameMessage("You have given " + Utils.formatPlayerNameForDisplay(name11) + " " + amount + " of " + ItemDefinitions.getItemDefinitions(item).name.toLowerCase());
					return true;
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
					return true;
				}

				/*
				 * Promote a player to moderator or admin
				 * 
				 * Usage: ::promote playerName Example: ::promote swirl
				 */
			case "promote":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					int newRights = target1.getRights() + 1;

					if (newRights == 1 || newRights == 2) {
						target1.setRights(newRights);
						target1.setStaff(true);
						target1.getPackets().sendGameMessage("You have been promoted to " + (newRights == 1 ? "moderator" : "administrator") + "!");
						player.getPackets().sendGameMessage("You have promoted " + Utils.formatPlayerNameForDisplay(name11) + " to " + (newRights == 1 ? "moderator" : "administrator") + "!");
						target1.getAppearence().generateAppearenceData();
						return true;
					} else {
						player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is already at the top!");
						return true;
					}
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
					return true;
				}

				/*
				 * Demote a player to normal or moderator
				 * 
				 * Usage: ::demote playerName Example: ::demote swirl
				 */
			case "demote":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					int newRights = target1.getRights() - 1;

					if (newRights == 1 || newRights == 0) {
						target1.setRights(newRights);
						target1.setStaff((newRights == 1 ? true : false));
						target1.getPackets().sendGameMessage("You have been demoted to " + (newRights == 1 ? "moderator" : "normal player") + "!");
						player.getPackets().sendGameMessage("You have demoted " + Utils.formatPlayerNameForDisplay(name11) + " to " + (newRights == 1 ? "moderator" : "normal player") + "!");
						target1.getAppearence().generateAppearenceData();
						return true;
					} else {
						player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is already at the bottom!");
						return true;
					}
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
					return true;
				}

				/*
				 * Teleport to a location
				 * 
				 * Usage: ::tele x y plane Example: ::tele 1000 1000 0
				 */
			case "tele":
				if (cmd.length < 3) {
					player.getPackets().sendPanelBoxMessage("Use: ::tele coordX coordY");
					return true;
				}
				try {
					player.resetWalkSteps();
					player.setNextWorldTile(new WorldTile(Integer.valueOf(cmd[1]), Integer.valueOf(cmd[2]), cmd.length >= 4 ? Integer.valueOf(cmd[3]) : player.getPlane()));
				} catch (NumberFormatException e) {
					player.getPackets().sendPanelBoxMessage("Use: ::tele coordX coordY plane");
				}
				return true;

				/*
				 * Unmute a player
				 * 
				 * Usage: ::unmute playerName Example: ::unmute swirl
				 */
			case "unmute":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setMuted(0);
					target1.getPackets().sendGameMessage("You've unmuted by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You unmuted " + Utils.formatPlayerNameForDisplay(name11) + ".");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setMuted(0);
					player.getPackets().sendGameMessage("You unmuted " + Utils.formatPlayerNameForDisplay(name11) + ".");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;
				/*
				 * Unjail a player
				 * 
				 * Usage: ::unjail playerName Example: ::unjail swirl
				 */
			case "unjail":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setJailed(0);
					target1.getControlerManager().startControler("JailControler");
					target1.getPackets().sendGameMessage("You've unjailed " + Utils.formatPlayerNameForDisplay(player.getUsername()) + ".");
					player.getPackets().sendGameMessage("You have unjailed " + Utils.formatPlayerNameForDisplay(name11) + " for 24 hours.");
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
				}
				return true;

				/*
				 * Give a player squeal of fortune spins
				 * 
				 * Usage: ::givespins playerName amount Example: ::givespins
				 * swirl 10
				 */
			case "givespins":
				name11 = cmd[1].substring(cmd[1].indexOf(" ") + 1);
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					try {
						target1.getSquealOfFortune().giveEarnedSpins(Integer.parseInt(cmd[2]));
						target1.getPackets().sendGameMessage("You were given " + cmd[2] + " spins by " + Utils.formatPlayerNameForDisplay(player.getUsername()) + ".");
						player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " " + cmd[2] + " spins.");
					} catch (NumberFormatException e) {
						return true;
					}
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
				}
				return true;

				/*
				 * Check another players bank
				 * 
				 * Usage: ::checkbank playerName Example: ::checkbank swirl
				 */
			case "checkbank":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					player.getPackets().sendItems(95, target1.getBank().getContainerCopy());
					player.getBank().openPlayerBank(target1);
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
				}
				return true;



				/*
				 * Search for the itemId of an item
				 * 
				 * Usage: ::getid itemName Example: ::getid dragon claws
				 */
			case "getid":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				ItemSearch.searchForItem(player, name11);
				return true;

				/*
				 * Search for the itemId of an item
				 * 
				 * Usage: ::getid itemName Example: ::getid dragon claws
				 */
			case "getnpc":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				NPCSearch.searchForNPC(player, name11);
				return true;

				/*
				 * Search for the itemId of an item
				 * 
				 * Usage: ::getid itemName Example: ::getid dragon claws
				 */
			case "getobject":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				ObjectSearch.searchForObject(player, name11);
				return true;

				/*
				 * Teleport to a player
				 * 
				 * Usage: ::teleto playerName Example: ::teleto swirl
				 */
			case "teleto":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					player.setNextWorldTile(target1);
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
				}
				return true;

				/*
				 * Teleport a player to you
				 * 
				 * Usage: ::teletome playerName Example: ::teletome swirl
				 */
			case "teletome":
				name1 = "";
				for (int i = 1; i < cmd.length; i++)
					name1 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				target = World.getPlayerByDisplayName(name1);
				if (target == null)
					player.getPackets().sendGameMessage("Couldn't find player " + name1 + ".");
				else {
					target.lock(15);
					final Player _target = target;
					WorldTasksManager.schedule(new WorldTask() {
						@Override
						public void run() {
							_target.setNextAnimation(new Animation(-1));
							_target.setNextWorldTile(player);

						}
					}, 5);
				}
				return true;
				/*
				 * Send an update timer for the server
				 * 
				 * Usage: ::update timeInSeconds Example: ::update 60
				 */
			case "update":
				if (cmd.length < 2) {
					World.safeShutdown(false, 60);
					return true;
				} else {
					try {
						World.safeShutdown(false, Integer.valueOf(cmd[1]));
					} catch (NumberFormatException e) {
						player.getPackets().sendGameMessage("Use: ::update timeInSeconds");
					}
					return true;
				}

				/*
				 * God yourself with lots of HP and high stats
				 * 
				 * Usage: ::god Example: ::god
				 */
			case "god":
				player.setHitpoints(Short.MAX_VALUE);
				player.getEquipment().setEquipmentHpIncrease(Short.MAX_VALUE - 990);
				for (int i = 0; i < 10; i++) {
					player.getCombatDefinitions().getBonuses()[i] = 50000;
				}
				for (int i = 14; i < player.getCombatDefinitions().getBonuses().length; i++) {
					player.getCombatDefinitions().getBonuses()[i] = 50000;
				}
				return true;

				/*
				 * Give a player GFX Designer rank
				 * 
				 * Usage: ::givegfx playerName Example: ::givegfx swirl
				 */
			case "givegfx":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setGraphicDesigner(true);
					target1.getPackets().sendGameMessage("You have been given graphic designer rank by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the graphic designer rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setGraphicDesigner(true);
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the graphic designer rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Give a player Donator rank
				 * 
				 * Usage: ::givedonator playerName Example: ::givedonator swirl
				 */
			case "givedonator":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setDonator(true);
					target1.getPackets().sendGameMessage("You have been given donator rank by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the donator rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setDonator(true);
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the donator rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Give a player Supreme Donator rank
				 * 
				 * Usage: ::givesupremedonator playerName Example: ::givesupremedonator
				 * Corleone
				 */
			case "givesupremedonator":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setSupremeDonator(true);
					target1.getPackets().sendGameMessage("You have been given supreme donator rank by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the supreme rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setSupremeDonator(true);
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the supreme donator rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Give a player Extreme Donator rank
				 * 
				 * Usage: ::giveexdonator playerName Example: ::giveexdonator
				 * swirl
				 */
			case "giveexdonator":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setExtremeDonator(true);
					target1.getPackets().sendGameMessage("You have been given extreme donator rank by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the extreme donator rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setExtremeDonator(true);
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the extreme donator rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Give a player Developer rank
				 * 
				 * Usage: ::givedev playerName Example: ::givedev swirl
				 */
			case "giverespected":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setRespected(true);
					target1.getPackets().sendGameMessage("You have been given Respected Member rank by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the Respected rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setRespected(true);
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the Respected rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Give a player Support rank
				 * 
				 * Usage: ::givesupport playerName Example: ::givesupport swirl
				 */
			case "givesupport":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setSupporter(true);
					target1.getPackets().sendGameMessage("You have been given Support Member rank by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the Support rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setSupporter(true);
					player.getPackets().sendGameMessage("You gave " + Utils.formatPlayerNameForDisplay(name11) + " the Support rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Take a players GFX Designer rank
				 * 
				 * Usage: ::takegfx playerName Example: ::takegfx swirl
				 */
			case "takegfx":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setGraphicDesigner(false);
					target1.getPackets().sendGameMessage("Your graphic designer rank was taken by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s graphic designer rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setGraphicDesigner(false);
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s graphic designer rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Take a players Donator rank
				 * 
				 * Usage: ::takedonator playerName Example: ::takedonator swirl
				 */
			case "takedonator":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setDonator(false);
					target1.getPackets().sendGameMessage("Your donator rank was taken by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s donator rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setDonator(false);
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s donator rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Take a players Extreme Donator rank
				 * 
				 * Usage: ::takeexdonator playerName Example: ::takeexdonator
				 * swirl
				 */
			case "takeexdonator":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setExtremeDonator(false);
					target1.getPackets().sendGameMessage("Your extreme donator rank was taken by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s extreme donator rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setExtremeDonator(false);
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s extreme donator rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Take a players supreme Donator rank
				 * 
				 * Usage: ::takesupremedonator playerName Example: ::takesupremedonator
				 * Corleone
				 */
			case "takesupremedonator":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setSupremeDonator(false);
					target1.getPackets().sendGameMessage("Your supreme donator rank was taken by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s supreme donator rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setSupremeDonator(false);
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s supreme donator rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Take a players Respected rank
				 * 
				 * Usage: ::takerespected playerName Example: ::takerespected swirl
				 */
			case "takerespected":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setRespected(false);
					target1.getPackets().sendGameMessage("Your Respected Member rank was taken by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s Respected rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setRespected(false);
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s Respected rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;

				/*
				 * Take a players Support rank
				 * 
				 * Usage: ::takesupport playerName Example: ::takesupport swirl
				 */
			case "takesupport":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setSupporter(false);
					target1.getPackets().sendGameMessage("Your Support rank was taken by " + Utils.formatPlayerNameForDisplay(player.getUsername()));
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s Support rank.");
				} else {
					name11 = Utils.formatPlayerNameForProtocol(name11);
					if (!SerializableFilesManager.containsPlayer(name11)) {
						player.getPackets().sendGameMessage("Account name " + Utils.formatPlayerNameForDisplay(name11) + " doesn't exist.");
						return true;
					}
					target1 = SerializableFilesManager.loadPlayer(name11);
					target1.setUsername(name11);
					target1.setSupporter(false);
					player.getPackets().sendGameMessage("You took " + Utils.formatPlayerNameForDisplay(name11) + "'s Support rank.");
					SerializableFilesManager.savePlayer(target1);
				}
				return true;
				/*
				 * Show your position in the world
				 * 
				 * Usage: ::mypos Example: ::mypos
				 */
			case "mypos":
				player.getPackets().sendGameMessage("X: " + player.getX() + " Y: " + player.getY() + " Plane: " + player.getPlane());
				player.getPackets().sendGameMessage("Region ID: " + player.getRegionId() + " Region X: " + player.getChunkX() + " Region Y: " + player.getChunkY());
				return true;

				/*
				 * Healing, dfire, summ, prayer, special restoration in one command
				 * 
				 * Usage: ::fun Example: ::fun
				 */
			case "fun":
				for (final Player p1 : World.getPlayers()) {
					if (p1 != null && Utils.getDistance(player, p1) < 9) {
						if (p1.isLocked())
							break;
						p1.setNextFaceWorldTile(new WorldTile(player.getX(), player.getY()-1, player.getPlane()));
						p1.lock();
						p1.setInvulnerable(true);
						WorldTasksManager.schedule(new WorldTask() {
							int step;
							@Override
							public void run() {
								if (step == 1) {
									p1.setNextGraphics(new Graphics(92));
									p1.heal(1000);
									p1.getPackets().sendGameMessage("Your LP has been restored!");
								}
								if (step == 3) {
									p1.setNextGraphics(new Graphics(2128));
									p1.getCombatDefinitions().restoreSpecialAttack(100);
									p1.getPackets().sendGameMessage("Your Special Attack has been restored!");
								}
								if (step == 5) {
									p1.setNextGraphics(new Graphics(2211));
									p1.getPrayer().setPrayerpoints((int) ((int) (player.getSkills().getLevelForXp(Skills.PRAYER) * 10)));
									p1.getPackets().sendGameMessage("Your Prayer has been restored!");
								}
								if (step == 7) {
									p1.setNextGraphics(new Graphics(2455));
									p1.addFireImmune(6000);
									p1.getPackets().sendGameMessage("You are now immune to dragonfire!");
								}
								if (step == 9) {
									p1.setNextGraphics(new Graphics(-1));
									p1.restoreRunEnergy();
									p1.getPackets().sendGameMessage("Your Run Energy has been restored!");
									p1.setInvulnerable(false);
									p1.unlock();
									stop();
								}
								step++;
							}
						},0, 1);
					}
				}
				return true;

				/*
				 * Spams yell for an important message
				 * 
				 * Usage: ::spamyell Example: ::spamyell message
				 */
			case "spamyell":
				message = "";
				for (int i = 1; i < cmd.length; i++) {
					message += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				Commands.sendYell(player, Utils.fixChatMessage(message), false);
				Commands.sendYell(player, Utils.fixChatMessage(message), false);
				Commands.sendYell(player, Utils.fixChatMessage(message), false);
				Commands.sendYell(player, Utils.fixChatMessage(message), false);
				Commands.sendYell(player, Utils.fixChatMessage(message), false);
				Commands.sendYell(player, Utils.fixChatMessage(message), false);
				Commands.sendYell(player, Utils.fixChatMessage(message), false);
				return true;

				/*
				 * Opens your bank anywhere
				 * 
				 * Usage: ::bank Example: ::bank
				 */
			case "bank":
				player.getBank().openBank();
				return true;


				/*
				 * Hides you
				 * 
				 * Usage: ::hide Example: hide
				 */
			case "hide":
				player.getAppearence().switchHidden();
				player.getPackets().sendGameMessage("Am I hidden? " + player.getAppearence().isHidden());
				return true;

				/*
				 * Spawns the 7 pengs
				 * 
				 * Usage: ::spawnpenguins Example: spawnpenguins
				 */
			case "spawnpenguins":
				World.spawnNPC(8110, player, -1, true, true);
				World.spawnNPC(8109, player, -1, true, true);
				World.spawnNPC(8108, player, -1, true, true);
				World.spawnNPC(8107, player, -1, true, true);
				World.spawnNPC(8106, player, -1, true, true);
				World.spawnNPC(8105, player, -1, true, true);
				World.spawnNPC(8104, player, -1, true, true);
				return true;

			case "removeshield":
			case "vulnerable":
				player.setInvulnerable(false);
				player.getPackets().sendGameMessage("<col=05f4d0>You are vulnerable again!", false);
				return true;

			case "shield":
			case "invulnerable":
				player.setInvulnerable(true);
				player.getPackets().sendGameMessage("<col=05f4d0>You are invulnerable!", false);
				return true;

			case "takeshield":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setInvulnerable(false);
					target1.getPackets().sendGameMessage("<col=05f4d0>You are vulnerable!", false);			
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
					return true;
				}
				return true;

			case "giveshield":
				name11 = "";
				for (int i = 1; i < cmd.length; i++) {
					name11 += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
				}
				target1 = World.getPlayerByDisplayName(name11);
				if (target1 != null) {
					target1.setInvulnerable(true);
					target1.getPackets().sendGameMessage("<col=05f4d0>You are invulnerable!", false);
					target1.setNextGraphics(new Graphics(2319));
					target1.setNextGraphics(new Graphics(2321));				
				} else {
					player.getPackets().sendGameMessage(Utils.formatPlayerNameForDisplay(name11) + " is either offline, or doesn't exist.");
					return true;
				}
				return true;

				/*
				 * Give yourself or a player completionist cape
				 * 
				 * Usage: ::comp playerName Example: ::comp swirl
				 */
			case "reset":
				if (cmd.length < 2) {
					for (int i = 0; i < 25; i++) {
						player.getSkills().setXp(i, Skills.MAXIMUM_EXP);
					}
				} else {
					try {
						player.getSkills().setXp(Integer.valueOf(cmd[1]), Skills.MAXIMUM_EXP);
					} catch (NumberFormatException e) {
						player.getPackets().sendGameMessage("Use: ::reset (optional:skillId)");
					}
				}
				return true;

			}
		}
		return false;
	}
}
